﻿using System;
using DataService.Enums;

namespace DataService.Structs;

public struct HistoryData : IComparable<HistoryData>
{
    public short ID;
    public QUALITIES Quality;
    public Storage Value;
    public DateTime TimeStamp;

    public HistoryData(short id, QUALITIES qualitie, Storage value, DateTime timeStamp)
    {
        ID = id;
        Quality = qualitie;
        Value = value;
        TimeStamp = timeStamp;
    }

    public override bool Equals(object obj)
    {
        if (obj == null) return false;
        if (obj is HistoryData)
        {
            return this == (HistoryData)obj;
        }
        else return false;
    }

    public override int GetHashCode()
    {
        return ID.GetHashCode() ^ TimeStamp.GetHashCode();
    }


    public static bool operator ==(HistoryData x, HistoryData y)
    {
        return x.ID == y.ID && x.TimeStamp == y.TimeStamp;
    }

    public static bool operator !=(HistoryData x, HistoryData y)
    {
        return x.ID != y.ID || x.TimeStamp != y.TimeStamp;
    }

    public static readonly HistoryData Empty = new HistoryData();

    public int CompareTo(HistoryData other)
    {
        int comp = TimeStamp.CompareTo(other.TimeStamp);
        return comp == 0 ? ID.CompareTo(other.ID) : comp;
    }
}
